#pragma once

#include <cstdint>
#include <stm32f407xx.h>

extern "C" {
void tim1_brk_tim9_irq_handler_backend();
}

namespace hw {

struct Timer9 {
  static void init();
  static void await(uint16_t prescale, uint16_t autoreload);
  static void reset(uint16_t prescale);
  static void cancel();
  static inline uint16_t read_reset() {
    auto value = static_cast<uint16_t>(TIM9->CNT);
    TIM9->CNT = 0;
    return value;
  }
};

} // namespace hw
